import { MenuParams, MenuListItem, AppMenuParam } from './model/systemModel';
import { defHttp } from '/@/utils/http/axios';
import type { AppRouteRecordRaw } from '/@/router/types';
import { MenuItemModel, ModuleRoleModel, MenuTreeModel } from './model/authModel';

enum Api {
  MenuPageList = '/admin/module/tree',
  InfoMenu = '/admin/module',
  ADDMenu = '/admin/module/add',
  UpdateMenu = '/admin/module/update',
  DelMenu = '/admin/module/del',
  ModuleID = '/admin/module/getUsefulIds',
  ModuleFirstList = '/admin/module/getUserMainModules',
  ModuleList = '/admin/module/getUserModules',
  ModuleAuthList = '/admin/module/getModuleUIInfo',
  ModulesRole = '/admin/module/getRoleModules',
  ModulesRoleUpdate = '/admin/module/updateRoleModules',
  ModulesRoleData = '/admin/role/getRoleDeptTree',
  ModulesRoleUpdateData = '/admin/role/updateRoleDeptTree',
  MenuClientTree = '/admin/module/list',
}
export const getMenuTree = (params?: MenuParams) =>
  defHttp.get<MenuTreeModel[]>({ url: Api.MenuPageList, params });

export const addMenuApi = (params: MenuListItem) => defHttp.post<any>({ url: Api.ADDMenu, params });

export const getMenuItemApi = (moduleId: number) =>
  defHttp.get<MenuItemModel>({ url: Api.InfoMenu + '/' + moduleId });

export const getMenuListApi = (params: { parentId: number }) =>
  defHttp.get<AppRouteRecordRaw[]>({ url: Api.ModuleList, params });

export const updateMenuApi = (params: MenuListItem) =>
  defHttp.post<boolean>({ url: Api.UpdateMenu, params });

export const deleteMenuApi = (id: string) => defHttp.post<any>({ url: Api.DelMenu + '/' + id });

export const getMenuInfoApi = (id: string) =>
  defHttp.get<MenuListItem>({ url: Api.InfoMenu + '/' + id });

export const searchModuleID = () => defHttp.get<any>({ url: Api.ModuleID });

export const getModuleFirstListApi = () =>
  defHttp.get<AppRouteRecordRaw[]>({ url: Api.ModuleFirstList });

export const getModuleAuthListApi = (moduleId: number) =>
  defHttp.get<any>({ url: Api.ModuleAuthList + '/' + moduleId });

export const getModulesRoleListApi = (params?: { roleId: number; client: number }) =>
  defHttp.get<ModuleRoleModel>({ url: Api.ModulesRole, params });

export const updateModulesRoleApi = ({ roleId, params }) =>
  defHttp.post<any>({ url: Api.ModulesRoleUpdate + '/' + roleId, params });

export const getModulesRoleListApiData = (moduleId: number) =>
  defHttp.get<any>({ url: Api.ModulesRoleData + '/' + moduleId });

export const updateModulesRoleApiData = ({ roleId, checkedKeys }) =>
  defHttp.post<any>({ url: Api.ModulesRoleUpdateData + '/' + roleId, params: { checkedKeys } });

export const getMenuClientTree = (params: AppMenuParam) =>
  defHttp.get<any>({ url: Api.MenuClientTree, params });
